@extends('admin.layout')

@section('content')
<div class="content-wrapper" style="min-height: 916px;">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
               	商品管理
                <small>列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>后台主页</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="active">列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box">
                        <div class="box-header">
                            <h3 class="box-title">快速查看商品列表</h3>
                        </div><!-- /.box-header -->
                        <div class="box-body">
							
						@if(session('info'))
							<div id="showHidden" class="alert alert-success alert-dismissable">
		                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
		                    <h4>	<i class="icon fa fa-check"></i> 提示!</h4>
		                    {{ session('info') }}
		                  </div>
						@endif

						 @if(session('error'))
                            <div id="showHidden" class="alert alert-danger alert-dismissable">
                            <button aria-hidden="true" data-dismiss="alert" class="close" type="button">x</button>
                                <h4><i class="icon fa fa-ban"></i>警告!</h4>
                                   {{ session('error') }} 
                            </div>
	                       @endif

						<div class="row">
						<form action="{{ url('admin/goods/index') }}" method="get">
							<div class="col-md-4">
								<div class="form-group form-group-sm">
									<select name="num" class="form-control">
		                                <option value="10"
										@if(!empty($request['num']) && $request['num'] == 10)
											selected="selected"
										@endif
		                                >10</option>
		                                <option value="20"
										@if(!empty($request['num']) && $request['num'] == 20)
											selected="selected"
										@endif
		                                >20</option>
		                                <option value="50"
										@if(!empty($request['num']) && $request['num'] == 50)
											selected="selected"
										@endif
		                                >50</option>
		                                <option value="100"
										@if(!empty($request['num']) && $request['num'] == 100)
											selected="selected"
										@endif
		                                >100</option>
		                                <option value="150"
										@if(!empty($request['num']) && $request['num'] == 150)
											selected="selected"
										@endif
		                                >150</option>
		                            </select>
	                            </div>
							</div>

							<div class="col-md-6 col-md-offset-2">
								<div class="input-group input-group-sm">
	                                <input type="text" value="{{ $request['keyword']  or '' }}" name="keyword" class="form-control">
				                    <span class="input-group-btn">
				                      <button class="btn btn-info btn-flat">搜索</button>
				                    </span>
	                            </div>
	                        </div>
	                     </form>
						</div>

						<div class="rot" style="height:10px"></div>


                            <table class="table table-bordered table-hover dataTable" id="example2" role="grid" aria-describedby="example2_info">
                                <thead>
                                <tr>
									<th>ID</th>
									<th>商品名称</th>
                                    <th>图片</th>
									<th>价格</th>
									<th>商品状态</th>
									<th>操作</th>

                                </tr>
                                </thead>
                                <tbody>
                                @foreach($data as $goods)
		                                <tr>
		                                    <td class='ids'>{{ $goods -> id}}</td>
		                                    <td class='name'>{{ $goods -> name}}</td>
                                            <td>
                                                <img  width = "80" height = '100' src = "{{ $goods -> img}}" />
                                            </td>

		                                    <td>{{ $goods -> price}}</td>
		                                    <td class="std">
		                                    	@if($goods -> is_delete == '0')
													下架
		                                    	@else
													上架
		                                    	@endif
		                                    </td>
		                                    <td>
		                                    <a href="{{url('/admin/goods/edit')}}/{{ $goods -> id}}">编辑</a> 
		                                    <span>|</span>
		                                    <a href="{{ url('/admin/goods/delete')}}/{{ $goods -> id}}">删除</a>
		                                    </td>
		                                </tr>
								@endforeach
                            </table>
                 
                            
                            <!-- 分页 -->

							{!! $data -> appends($request) -> render() !!}
                        </div><!-- /.box-body -->
                    </div><!-- /.box -->
                </div><!-- /.col -->
            </div><!-- /.row -->
        </section><!-- /.content -->
    </div>

    <script type="text/javascript">
    	
    	window.onload = function() 
    	{

            //自动清除提示框
            setTimeout("$('#showHidden').hide( )",3000); 

    		/*// alert($);
    			$.ajaxSetup({
    				headers: {
    					'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    				}
    			});

    			//添加事件
    			
    			//鼠标移入事件
    			$('.std, .name').on('mouseover', function(){

    				$(this).css({cursor:'pointer', color:'blue'});
    			})

    			//鼠标移出事件
    			$('.std, .name').on('mouseout', function(){

    				$(this).css({cursor:'default', color:'black'});
    			})
    			

    			$('.std').on('click', function(){

    				var std = $(this);
    				var id = $(this).parent().find('.ids').html();
    				// var id = $(this ).parent().children().first().html();
    				
    				// alert(id);
    				$.post('/admin/goods/ajaxUpdate',{id:id},function(data){

                            alert(data);

    					if(data =='0')
    					{
    						std.html('上架');
    					}else if(data == '2')
    					{
    						std.html('下架');
    					}
    				},'json');

    			});

    			function dblClick()
    			{
    				var td = $(this);
    				//获取原ID
    				var id = td.prev().html();
    				//获取原value值
    				var name= td.html();

    				var inp = $('<input type="text" />');
    				inp.val(name);

    				//将表单放到TD中
    				td.html(inp);
    				//自动对焦
    				inp.select();
    				//失去焦点
    				inp.blur(function()
    				{
                    
    					//获取新值
    					var newName = inp.val();

    					if(name == newName)
    					{
    						// alert('你脑子有病');
    						td.html(name);
    						//添加事件
    						td.dblclick(dblClick);
    						return ;
    					}

    					//ajax
    					$.post('/admin/goods/ajaxUsername',{id:id,name:newName},
    						function(data)
    						{
    							if(data == '1')
    							{
    								alert('商品名已存在');
    								td.html(name);
    							}else if(data == '0')
    							{
    								td.html(newName);
    							}else
    							{
    								alert('商品修改失败');
    								td.html(name);
    							}
    						},'json');	
    					//添加事件
    					td.dblclick(dblClick);
    				});

    				//清除事件
    				td.unbind('dblclick');
    			}

    			//双击修改商品名
    			$('td[class=name]').on('dblclick',dblClick);
    	}
*/
    </script>

@endsection